package base

import "github.com/slclub/go-tips"

type ModelTime struct {
	CreatedAt int `gorm:"autoCreateTime"`
	UpdatedAt int `gorm:"autoUpdateTime"`
	DeletedAt int `gorm:"softDelete:flag"`
}

func (self *ModelTime) ConvFromMap(m map[string]any) {
	if val, ok := m["CreatedAt"]; ok {
		self.CreatedAt = tips.Int(val)
	}
	if val, ok := m["UpdatedAt"]; ok {
		self.UpdatedAt = tips.Int(val)
	}
	if val, ok := m["DeletedAt"]; ok {
		self.DeletedAt = tips.Int(val)
	}
}

func (self *ModelTime) ConvToMap(m map[string]any) {
	m["CreatedAt"] = self.CreatedAt
	m["UpdatedAt"] = self.UpdatedAt
	m["DeletedAt"] = self.DeletedAt
}

//// jinzhu gorm
//type ModelID struct {
//	ID uint `gorm:"primaryKey;AUTO_INCREMENT"`
//}

type ModelID struct {
	ID uint `gorm:"primaryKey;column:id;autoIncrement"`
}

func (self *ModelID) ConvFromMap(m map[string]any) {
	if val, ok := m["ID"]; ok && self.ID == 0 {
		self.ID = uint(tips.Any2Int64(val))
	}
}

type ModelSubmmit struct {
	Submit   int    `gorm:"type:int(6);comment:审核状态 1=待审状态 2=驳回 3=审核"`
	Submiter string `gorm:"size:128;comment:审核人-驳回人;"`
	Reason   string `gorm:"size:255;comment:缘由;"`
	SubmitAt int    `gorm:"type:int(10);comment:审核时间;"`
}

func (self *ModelSubmmit) ConvFromMap(m map[string]any) {
	// 审核字段
	if val, ok := m["Submit"]; ok {
		self.Submit = (tips.Int(val))
	}
	if val, ok := m["Submiter"]; ok {
		self.Submiter = tips.String(val)
	}
	if val, ok := m["Reason"]; ok {
		self.Reason = tips.String(val)
	}
	if val, ok := m["SubmitAt"]; ok {
		self.SubmitAt = tips.Int(val)
	}
}

type UUIDR struct {
	UUID string `gorm:"size:128;column:uuid;type:varchar(64);"`
}

func (self *UUIDR) ConvFromMap(m map[string]any) {
	if val, ok := m["UUID"]; ok {
		self.UUID = tips.String(val)
	}
}
